/*** 报表处理对象 @param {[msgObj]} prcscd 为处理码,operid 操作人ID,msgObj 发送的JSON对象(可选) */  
function msgTool(url,msgObj){ 
	this._url = url;
	if(msgObj!=null){
		this._msgObj = msgObj;
	}else{
		this._msgObj = new Object();	
	}
}
msgTool.prototype = {
		_errorcode:"1000",  
		/** 发送报文字符串 **/
		_rsgStr:"",
		/*** 设置向后台发送的key,value * @param {key,value}  */  
		setMsg:function(url,sendStr,groupCode){
			this._sendStr = sendStr;
			this._url = url;
			this._groupCode = groupCode;
		},
		setFiledValue:function (key,value){
			this._msgObj[key] = value;
		},
		/*** 向后台的报文转化成字符串 * @param {key,value}  */  
		toString:function(obj){
			return JSON.stringify(this._msgObj);   
		}, 
		//发送报文 *@param{url,bodyObj,callback)}  *url:请求地址 *bodyObj:请求数据 *callback:回调函数
		sendMsg:function(url,bodyObj,callback){
			 
			this._msgObj = JSON.stringify({"head":{},"body":bodyObj});
 			this._url = path+"/"+url+"?mspj-mall-admin=1";
			var ttkn2 = getCookie("ttkn2");
 			$.ajax({
				type:"POST",//提交数据的类型 POST GET
				url:this._url,
				headers:{
					"infoq":"ch=eshop;e=p",
					"ttkn2":ttkn2
				},
				data:this._msgObj,  //提交的数据
				async:false,
				timeout : 60000, //超时时间设置，单位毫秒
				datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
				//在请求之前调用的函数
				beforeSend:function(){
 					 
				},
				success:function(data){ //成功返回之后调用的函数  
				//	alert("data值："+data)
 					var rsObj = null;
					if(msg.isJson(data)){
						rsObj = data 
					}else{
						try{  
						rsObj = JSON.parse(data);
						}catch(e){
							rsObj = eval('['+data+']')
						}
					}
					console.log("resMsg:"+data);
					var retCode = rsObj.head.retCode ;
					if(retCode !='0000'){
						alert(rsObj.head.retMsg);
						return ;
					}
					if(callback!=undefined) 	callback(rsObj);
					return rsObj;
				},
 				error: function(){ //调用出错执行的函数   //请求出错处理
  					console.log("请检查网络问题！")
					return ;
				}
			});
		},
		// 弹出错误对话框
		showErrorMsg:function(msg){
			//$.messager.alert('温馨提示',msg,'error');
		},
		showAlert:function(msg){
			//$.messager.alert('温馨提示',msg);
		},
		showloading:function(id,msg){

		},
		hideloading:function(id){

		},isJson:function(obj){
			var isjson = typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length; 
			console.log(isjson)
			return isjson;
		}
}
function reLogin(msg){
 }

function setCookie(name,value) 
{ 
	var Days = 30; 
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000); 
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
} 

function getCookie(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;

}